#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_set>
using namespace std;

class Solution{
    public:
    //out of memory
    bool ans1(string s, string t){
        unordered_map<char, char> map1;
        unordered_map<char, char> map2;
        int len = s.size();
        for(int i = 0; i != len; i++){
            map1[s[i]] = t[i];
            map2[t[i]] = s[i];
        }
        string temp1 = "";
        string temp2 = "";
        for(int i = 0; i != len; i++){
            temp1 = temp1 + map1[s[i]];
            temp2 = temp2 + map2[t[i]];
        }
        int ret1 = temp1.compare(t);
        int ret2 = temp2.compare(s);
        if(ret1 == 0 && ret2 == 0){
            return true;
        }else{
            return false;
        }
    }

    bool ans2(string s, string t){
        unordered_map<char, char> map;
        int len = s.size();
        for(int i = 0; i != len; i++){
            map[s[i]] = t[i];
        }
        string temp = "";
        for(int i = 0; i != len; i++){
            temp = temp + map[s[i]];
        }
        int ret1 = temp.compare(t);
        map.clear();
        temp.clear();
        for(int i = 0; i != len; i++){
            map[t[i]] = s[i];
        }
        for(int i = 0; i != len; i++){
            temp = temp + map[t[i]];
        }
        int ret2 = temp.compare(s);
        if(ret1 == 0 && ret2 == 0){
            return true;
        }else{
            return false;
        }
    }
};

void test1(){
    Solution s;
    string str1 = "egg";
    string str2 = "add";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

void test2(){
    Solution s;
    string str1 = "foo";
    string str2 = "bar";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

void test3(){
    Solution s;
    string str1 = "paper";
    string str2 = "title";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}